<?php
namespace Admin\Controller;
use Think\Controller;
class CategoryController extends CommonController {
    public function lst(){
		$mod=D('category');
		$lis= $mod->select();
		$this->assign('lis',$lis);// 赋值数据集
		$this->display('lst');
	}
	
	
	public function del(){
		$mod=D('category');
		if($mod->delete(I('id'))){
			$this->success("删除文章栏目成功！",U('lst'));
		}else{
			$this->error("删除文章栏目失败！");
		}
	}
	

	
	public function add() {
				$category = M('category'); //实例化数据库
				if (!empty($_POST)) {
					$category->create(); //收集post表单数据
					//判断是否是帮助栏目，并修改数据
					if($category->type=='on'){
						$category->type=1;
					}else{
						$category->type=0;
					}
					$str = $category->add(); //添加数据
					if ($str) {
								$this->success('文章栏目添加成功！', U('lst'));
					} else {
								$this -> error('文章栏目添加失败！', U('add'));
					}
			} else {
				$this->display(); //没有POST显示空模板
			}
	}
	
	
	
	public function edit(){
		$category=M('category');
		if(IS_POST){
			if($category->create()){
				if($category->type =='on'){
					$category->type=1;
				}else{
					$category->type=0;
				}
				if($category->save()!==false){
					$this->success("修改文章栏目成功！",U('lst'));
				}else{
					$this->error("修改文章栏目失败！");
				}
			}
			return ;
		}
		$categorys = $category->find(I('id'));
		$this->assign("categorys",$categorys);
		$this->display();
		
	}
}